package com.monlyu.action.system;

import java.util.Map;

import com.google.common.collect.Maps;
import com.monlyu.action.BaseAction;
import com.monlyu.annotation.ActionAnno;
import com.monlyu.bean.EnumsBean;
import com.monlyu.bo.EnumsBo;
import com.monlyu.util.FtlUtil;
import com.monlyu.util.LogUtil;
import com.monlyu.vo.Enums;

/********************************************************************************
 * 
 * <b>功能描述☞</b>对所有的枚举类型进行操作<br>
 * 
 * <b>开发公司☞</b>重庆唯尼科技有限公司<br>
 * <b>版权☞</b>本文件归重庆唯尼科技有限公司所有<br>
 * <b>项目名☞</b>monlyu<br>
 * <b>文件路径☞</b>com.monlyu.action.system.EdlitEnumsAction.java<br>
 * <b>开发日期☞</b>2010-2-2 <br>
 * 
 * @author monlyu
 * @since JDK 5
 * @version 1.0.8
 * 
 ********************************************************************************/
public class EdlitEnumsAction extends BaseAction {

	public static final String ZZMM_TYPE = "zzmm.type";
	public static final String DEGREE_TYPE = "degree.type";
	public static final String BROADCAST_ERROR_TYPE = "broadcastError.errorType";
	public static final String DEVICES_TYPE = "devices.type";
	public static final String ZLSTATUS_TYPE = "zlstatus.type";
	public static final String NEWS_FROM_TYPE = "newsFrom.type";
	public static final String MSGFROM_TYPE = "msgFrom.type";
	public static final String START_TYPE = "start.type";
	public static final String MANUSTYPE_TYPE = "manustype.type";
	public static final String DEPT_TYPE = "dept.type";
	public static final String CHANNEL_TYPE = "channel.type";
	public static final String MANUSCRIPT_TYPE = "manuscript.type";
	public static final String SUBMATTER_TYPE = "submatter.typet";
	public static final String REGION_TYPE = "region.type";
	public static final String SCORE = "score";

	private String html;
	private Enums enums;
	private EnumsBo enumsBo;

	private static Map<String, EnumsBean> ENUM_TYPES_MAPS = Maps.newLinkedHashMap();
	

	static {
		if (ENUM_TYPES_MAPS.isEmpty()) {
			ENUM_TYPES_MAPS.put(DEPT_TYPE, new EnumsBean(DEPT_TYPE, EnumsBean.HASSUPER_YES, EnumsBean.SHOWVAL_NO,"部门名称", "是否有效", "隶属于", "备注信息"));// 部门信息维护
			ENUM_TYPES_MAPS.put(CHANNEL_TYPE, new EnumsBean(CHANNEL_TYPE, EnumsBean.HASSUPER_NO,EnumsBean.SHOWVAL_NO, "频道名称", "是否有效", "备注信息"));// 频道信息
			ENUM_TYPES_MAPS.put(MANUSCRIPT_TYPE, new EnumsBean(MANUSCRIPT_TYPE, EnumsBean.HASSUPER_NO,EnumsBean.SHOWVAL_NO, "类型名称", "是否有效", "类型备注信息"));// 稿件类型
			ENUM_TYPES_MAPS.put(SUBMATTER_TYPE, new EnumsBean(SUBMATTER_TYPE, EnumsBean.HASSUPER_NO,EnumsBean.SHOWVAL_NO, "题材名称", "是否有效", "备注信息"));// 题材信息维护
			ENUM_TYPES_MAPS.put(MANUSTYPE_TYPE, new EnumsBean(MANUSTYPE_TYPE, EnumsBean.HASSUPER_NO,EnumsBean.SHOWVAL_NO, "类别名称", "是否有效", "备注信息"));// 稿件类别
			ENUM_TYPES_MAPS.put(START_TYPE, new EnumsBean(START_TYPE, EnumsBean.HASSUPER_NO,EnumsBean.SHOWVAL_YES, "等级名称", "等级分数", "是否有效", "备注信息"));// 稿件等级
			ENUM_TYPES_MAPS.put(MSGFROM_TYPE, new EnumsBean(MSGFROM_TYPE, EnumsBean.HASSUPER_NO,EnumsBean.SHOWVAL_NO, "消息来源名称", "是否有效", "备注信息"));// 消息来源设置
			ENUM_TYPES_MAPS.put(NEWS_FROM_TYPE, new EnumsBean(NEWS_FROM_TYPE, EnumsBean.HASSUPER_NO,EnumsBean.SHOWVAL_NO, "新闻来源地", "是否有效", "备注信息"));// 新闻来源设置
			ENUM_TYPES_MAPS.put(ZLSTATUS_TYPE, new EnumsBean(ZLSTATUS_TYPE, EnumsBean.HASSUPER_NO,EnumsBean.SHOWVAL_NO, "资料状态名称", "是否有效", "备注信息"));// 资料状态设置
			ENUM_TYPES_MAPS.put(DEVICES_TYPE, new EnumsBean(DEVICES_TYPE, EnumsBean.HASSUPER_NO,EnumsBean.SHOWVAL_NO, "设备类别名称", "是否有效","隶属于", "备注信息"));// 设备 类别设置
			ENUM_TYPES_MAPS.put(BROADCAST_ERROR_TYPE, new EnumsBean(DEVICES_TYPE, EnumsBean.HASSUPER_NO,EnumsBean.SHOWVAL_NO, "错误名称", "是否有效", "备注信息"));// 错误类型设置
			ENUM_TYPES_MAPS.put(DEGREE_TYPE, new EnumsBean(DEGREE_TYPE, EnumsBean.HASSUPER_NO,EnumsBean.SHOWVAL_NO, "学历名称", "是否有效", "备注信息"));// 错误类型设置
			ENUM_TYPES_MAPS.put(ZZMM_TYPE, new EnumsBean(ZZMM_TYPE, EnumsBean.HASSUPER_NO,EnumsBean.SHOWVAL_NO, "政治面貌", "是否有效", "备注信息"));// 错误类型设置
			ENUM_TYPES_MAPS.put(SCORE, new EnumsBean(SCORE, EnumsBean.HASSUPER_NO,EnumsBean.SHOWVAL_NO, "分数", "是否有效", "备注信息"));// 分数信息维护
			ENUM_TYPES_MAPS.put(REGION_TYPE, new EnumsBean(REGION_TYPE, EnumsBean.HASSUPER_NO,EnumsBean.SHOWVAL_NO, "地域名称", "是否有效", "备注信息"));// 所属地域维护
		}
	}

	public void setEnumsBo(EnumsBo enumsBo) {
		this.enumsBo = enumsBo;
	}

	public Enums getEnums() {
		return enums;
	}

	public void setEnums(Enums enums) {
		this.enums = enums;
	}

	public String getHtml() {
		return html;
	}

	/**
	 * 跳转到编辑页面
	 * 
	 * @author monlyu
	 * @since 2010-2-2
	 */
	public String toEdit() {
		EnumsBean bean = ENUM_TYPES_MAPS.get(enums.getType());
		Map<String, Object> data = Maps.newHashMap();
		data.put("enums", enumsBo.getEnumsByType(enums.getType()));
		data.put("enumsType", enums.getType());
		data.put("hasSuper", bean.isHasSuper());
		data.put("showVal", bean.isShowVal());
		data.put("show", bean.getShow());
		if (bean.isHasSuper()) {
			data.put("supor", enumsBo.getSuper(enums.getType()));
		}
		try {
			html = FtlUtil.render2Ftl(data, "enumConfig.ftl");
		} catch (Exception e) {
			LogUtil.log(getClass()).warn(e.toString());
		}
		return view("enums.jsp");
	}

	/**
	 * @author monlyu
	 * @since 2009-12-27
	 */
	@Override
	@ActionAnno(readOnly = false)
	public String execute() throws Exception {
		String flag = "";
		if (enums != null && enums.getId() != null) {
			flag = "u";
		} else {
			flag = "a";
		}
		if (enums.getSupor() != null && enums.getSupor().getId() == null) {
			enums.setSupor(null);
		}
		enumsBo.save(enums);
		return ajax(flag + enums.getId());
	}
}